﻿using System;
using System.Data;
using System.Text;
using System.Data.OracleClient;
using DBUtility;//请先添加引用
using XCLib.Log;
namespace FiberRMS.DAL.AlarmManager
{
	/// <summary>
	/// 数据访问类ALARM_GUIFILTERMAP。
	/// </summary>
	public class ALARM_GUIFILTERMAP
	{
		public ALARM_GUIFILTERMAP()
		{}
		#region  成员方法
        public DataTable GetTransUGM(string userid)
        {
            string strSql = "select guifiltername, ar.resourcecnname,"; 
                strSql += "CASE ugfn.alarmtype WHEN '0' THEN '服务质量告警' ";
                strSql += "WHEN '1' THEN '设备告警' WHEN '2' THEN '通信告警' WHEN '3' THEN '环境告警' WHEN '4' THEN '处理错误告警' ELSE '未知告警' END alarmtype, ";
                strSql += "CASE ugfn.alarmlevel WHEN 'critical' THEN '严重告警' WHEN 'major' THEN '主要告警' WHEN 'minor' THEN '次要告警' WHEN 'warning' THEN '警告告警' WHEN 'other' THEN '其他告警' ELSE '未知告警' END alarmlevel, vendor, isused " ;
                strSql += " FROM alarm_guifiltermap ugfn,alarm_resource ar ";
                strSql += " WHERE ugfn.resourceid = ar.resourceid and userid = '"+ userid +"'";
                DataTable dt = null;
                try
                {
                    dt = OracleHelper.Query(strSql).Tables[0];
                }
                catch (System.Data.OracleClient.OracleException ex)
                {
                    CLogSingleton.PolicyOneLog(ex.Message,"获得呈现规则列表异常",strSql);
                    dt = null;
                }
                return dt;
        }
		/// <summary>
		/// 是否存在该记录
		/// </summary>
		public bool Exists(string GUIFILTERNAME)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select count(1) from ALARM_GUIFILTERMAP");
			strSql.Append(" where GUIFILTERNAME=:GUIFILTERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":GUIFILTERNAME", OracleType.VarChar,50)};
			parameters[0].Value = GUIFILTERNAME;

			return OracleHelper.Exists(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 增加一条数据
		/// </summary>
		public void Add(FiberRMS.Model.AlarmManager.ALARM_GUIFILTERMAP model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("insert into ALARM_GUIFILTERMAP(");
			strSql.Append("USERID,GUIFILTERNAME,RESOURCEID,ALARMTYPE,ALARMLEVEL,VENDOR,ISUSED)");
			strSql.Append(" values (");
			strSql.Append(":USERID,:GUIFILTERNAME,:RESOURCEID,:ALARMTYPE,:ALARMLEVEL,:VENDOR,:ISUSED)");
			OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":GUIFILTERNAME", OracleType.VarChar,50),
					new OracleParameter(":RESOURCEID", OracleType.VarChar,50),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,20),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,20),
					new OracleParameter(":VENDOR", OracleType.VarChar,200),
					new OracleParameter(":ISUSED", OracleType.VarChar,2)};
			parameters[0].Value = model.USERID;
			parameters[1].Value = model.GUIFILTERNAME;
			parameters[2].Value = model.RESOURCEID;
			parameters[3].Value = model.ALARMTYPE;
			parameters[4].Value = model.ALARMLEVEL;
			parameters[5].Value = model.VENDOR;
			parameters[6].Value = model.ISUSED;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}
		/// <summary>
		/// 更新一条数据
		/// </summary>
		public void Update(FiberRMS.Model.AlarmManager.ALARM_GUIFILTERMAP model)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("update ALARM_GUIFILTERMAP set ");
			strSql.Append("USERID=:USERID,");
			strSql.Append("RESOURCEID=:RESOURCEID,");
			strSql.Append("ALARMTYPE=:ALARMTYPE,");
			strSql.Append("ALARMLEVEL=:ALARMLEVEL,");
			strSql.Append("VENDOR=:VENDOR,");
			strSql.Append("ISUSED=:ISUSED");
			strSql.Append(" where GUIFILTERNAME=:GUIFILTERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":USERID", OracleType.VarChar,50),
					new OracleParameter(":GUIFILTERNAME", OracleType.VarChar,50),
					new OracleParameter(":RESOURCEID", OracleType.VarChar,50),
					new OracleParameter(":ALARMTYPE", OracleType.VarChar,20),
					new OracleParameter(":ALARMLEVEL", OracleType.VarChar,20),
					new OracleParameter(":VENDOR", OracleType.VarChar,200),
					new OracleParameter(":ISUSED", OracleType.VarChar,2)};
			parameters[0].Value = model.USERID;
			parameters[1].Value = model.GUIFILTERNAME;
			parameters[2].Value = model.RESOURCEID;
			parameters[3].Value = model.ALARMTYPE;
			parameters[4].Value = model.ALARMLEVEL;
			parameters[5].Value = model.VENDOR;
			parameters[6].Value = model.ISUSED;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}

		/// <summary>
		/// 删除一条数据
		/// </summary>
		public void Delete(string GUIFILTERNAME)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("delete ALARM_GUIFILTERMAP ");
			strSql.Append(" where GUIFILTERNAME=:GUIFILTERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":GUIFILTERNAME", OracleType.VarChar,50)};
			parameters[0].Value = GUIFILTERNAME;

			OracleHelper.ExecuteSql(strSql.ToString(),parameters);
		}


		/// <summary>
		/// 得到一个对象实体
		/// </summary>
		public FiberRMS.Model.AlarmManager.ALARM_GUIFILTERMAP GetModel(string GUIFILTERNAME)
		{
			
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select USERID,GUIFILTERNAME,RESOURCEID,ALARMTYPE,ALARMLEVEL,VENDOR,ISUSED from ALARM_GUIFILTERMAP ");
			strSql.Append(" where GUIFILTERNAME=:GUIFILTERNAME ");
			OracleParameter[] parameters = {
					new OracleParameter(":GUIFILTERNAME", OracleType.VarChar,50)};
			parameters[0].Value = GUIFILTERNAME;

			FiberRMS.Model.AlarmManager.ALARM_GUIFILTERMAP model=new FiberRMS.Model.AlarmManager.ALARM_GUIFILTERMAP();
			DataSet ds=OracleHelper.Query(strSql.ToString(),parameters);
			if(ds.Tables[0].Rows.Count>0)
			{
				model.USERID=ds.Tables[0].Rows[0]["USERID"].ToString();
				model.GUIFILTERNAME=ds.Tables[0].Rows[0]["GUIFILTERNAME"].ToString();
				model.RESOURCEID=ds.Tables[0].Rows[0]["RESOURCEID"].ToString();
				model.ALARMTYPE=ds.Tables[0].Rows[0]["ALARMTYPE"].ToString();
				model.ALARMLEVEL=ds.Tables[0].Rows[0]["ALARMLEVEL"].ToString();
				model.VENDOR=ds.Tables[0].Rows[0]["VENDOR"].ToString();
				model.ISUSED=ds.Tables[0].Rows[0]["ISUSED"].ToString();
				return model;
			}
			else
			{
				return null;
			}
		}

		/// <summary>
		/// 获得数据列表
		/// </summary>
		public DataSet GetList(string strWhere)
		{
			StringBuilder strSql=new StringBuilder();
			strSql.Append("select USERID,GUIFILTERNAME,RESOURCEID,ALARMTYPE,ALARMLEVEL,VENDOR,ISUSED ");
			strSql.Append(" FROM ALARM_GUIFILTERMAP ");
			if(strWhere.Trim()!="")
			{
				strSql.Append(" where "+strWhere);
			}
			return OracleHelper.Query(strSql.ToString());
		}

		/*
		/// <summary>
		/// 分页获取数据列表
		/// </summary>
		public DataSet GetList(int PageSize,int PageIndex,string strWhere)
		{
			OracleParameter[] parameters = {
					new OracleParameter(":tblName", OracleType.VarChar, 255),
					new OracleParameter(":fldName", OracleType.VarChar, 255),
					new OracleParameter(":PageSize", OracleType.Number),
					new OracleParameter(":PageIndex", OracleType.Number),
					new OracleParameter(":IsReCount", OracleType.Clob),
					new OracleParameter(":OrderType", OracleType.Clob),
					new OracleParameter(":strWhere", OracleType.VarChar,1000),
					};
			parameters[0].Value = "ALARM_GUIFILTERMAP";
			parameters[1].Value = "ID";
			parameters[2].Value = PageSize;
			parameters[3].Value = PageIndex;
			parameters[4].Value = 0;
			parameters[5].Value = 0;
			parameters[6].Value = strWhere;	
			return OracleHelper.RunProcedure("UP_GetRecordByPage",parameters,"ds");
		}*/

		#endregion  成员方法
	}
}


